package top.whysu.rongcloud.controller;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.whysu.rongcloud.dto.http.Response;
import top.whysu.rongcloud.dto.rongcloud.friendship.AccountRequestDTO;
import top.whysu.rongcloud.po.RongCloudUserPO;
import top.whysu.rongcloud.service.RongCloudUserService;
import top.whysu.rongcloud.util.ResponseUtil;

import javax.annotation.Resource;

/**
 * 融云用户
 */
@RestController
@RequestMapping(value = "/rongCloud/user")
public class RongCloudUserController {

    @Resource
    RongCloudUserService rongCloudUserService;

    /**
     * 根据账号Account查找
     */
    @PostMapping("/findByAccount")
    public Response<RongCloudUserPO> findByAccount(@Validated AccountRequestDTO requestDTO) {
        RongCloudUserPO userExpand = rongCloudUserService.findByAccount(requestDTO.getAccount());
        return ResponseUtil.getSuccessResponse(userExpand);
    }

    /**
     * 保存账号
     */
    @PostMapping("/save")
    public Response save(@RequestBody @Validated RongCloudUserPO newUser) {
        rongCloudUserService.updateOrInsertByAccount(newUser);
        return ResponseUtil.getSuccessResponse();
    }

}


